<?php

declare(strict_types=1);

namespace App\Request\Index;

use App\Request\BaseCommonRequest;
use Hyperf\Context\Context;
use Hyperf\Validation\Request\FormRequest;

class UserSearchRequest extends BaseCommonRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'page' => 'required|gt:0',
            'keyword' => 'required',
            'from' => 'required',
            'version_code' => 'required',
            'channel' => 'required'
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     */
    public function messages(): array
    {
        $language = Context::get('language', 'en');
        if ($language == 'zh-cn') {
            return [
                'page.required' => '页码不能为空',
                'page.gt' => '页码必须大于0',
                'keyword.required' => '查询关键词不能为空',
                'from.required' => '系统类型不能为空',
                'version_code.required' => '版本号不能为空',
                'channel.required' => '渠道不能为空'
            ];
        } elseif ($language == 'zh-hk') {
            return [
                'page.required' => '頁碼不得為空',
                'page.gt' => '頁碼必須大於0',
                'keyword.required' => '查詢關鍵字不得為空',
                'from.required' => '系統類型不得為空',
                'version_code.required' => '版本號不能為空',
                'channel.required' => '渠道不能为空'
            ];
        } else {
            return [
                'page.required' => 'Page cannot be empty',
                'page.gt' => 'Page must be greater than 0',
                'keyword.required' => 'Search keywords cannot be empty',
                'from.required' => 'System type cannot be empty',
                'version_code.required' => 'Version code cannot be empty',
                'channel.required' => 'Channel cannot be empty'
            ];
        }

    }

}